<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>04 图片版时钟</title>
    <style>
        body {
            background: pink;
            color: #fff;
            font-size: 60px;
        }
    </style>
</head>
<body>
    <div id="time"></div>
</body>
<script src="../common.js"></script>
<script>

    (function () {

        var time = document.getElementById('time');
        function getTime() {

            var date = new Date();
            var hour = date.getHours(); // 时
            var mins = date.getMinutes(); // 分
            var sec = date.getSeconds(); // 秒

            var str = '' + toDb(hour) + toDb(mins) + toDb(sec);
            var html = '';
            var num = 0;

            for (var i in str) {
                num++;
                html += `<img src="../img/${str[i]}.png" alt="">`;

                if (num % 2 == 0) {
                    html += ':';
                }
            }

            html = html.slice(0,-1);

            console.log(html);

            time.innerHTML = html;
        }

        getTime();

        setInterval(getTime, 1000);

    })();

</script>
</html>